<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/">#include <xsl:text>&lt;cstddef&gt;</xsl:text>
/* setup return types that might not be defined */

#ifndef GL_VERSION_2_0
typedef char GLchar;
#endif

#ifndef GL_VERSION_1_5
typedef ptrdiff_t GLintptr;
typedef ptrdiff_t GLsizeiptr;
#endif

#ifndef GL_NV_half_float
typedef unsigned short GLhalfNV;
#endif

#ifndef GL_ARB_vertex_buffer_object
typedef ptrdiff_t GLintptrARB;
typedef ptrdiff_t GLsizeiptrARB;
#endif

#ifndef GL_ARB_shader_objects
typedef int GLhandleARB;
typedef char GLcharARB;
#endif

#ifndef GL_EXT_timer_query
typedef signed long long GLint64EXT;
typedef unsigned long long GLuint64EXT;
#endif

#ifdef _WIN32
// gl/gl defines GL_PHONG_WIN and GL_PHONG_HINT_WIN for us
#define GL_WIN_phong_shading              1

// gl/gl.h defines GL_FOG_SPECULAR_TEXTURE_WIN
#define GL_WIN_specular_fog               1

// defines GL_BYTE which is defined in gl/gl.h on windows
#define GL_OES_byte_coordinates           1
#endif


#define NAME_EMPTY(x)
#define FUNC_EMPTY(x, y, z, w)
#define END_EMPTY()
#define CONST_EMPTY(x, y)

      <xsl:for-each select="extensions/gl/extension">

#ifndef <xsl:value-of select="@name"/>
#define <xsl:value-of select="@name"/> 1
#define EXTENSION_<xsl:value-of select="@name" />(NAME, FUNC, CONST, END) \
  NAME(<xsl:value-of select="@name"/>) \
<xsl:apply-templates select="functions/function" />
<xsl:apply-templates select="constants/constant" />  END()
#else
#define EXTENSION_<xsl:value-of select="@name" />(NAME, FUNC, CONST, END)
#endif
    </xsl:for-each>

#define ALL_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:for-each>

#define ONLY_VERSION MAX_VERSION_EXTENSIONS
#define VERSION_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>

#define VERSION_1_2 VERSION_1_2_EXTENSIONS
#define VERSION_1_2_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define VERSION_1_3 VERSION_1_3_EXTENSIONS
#define VERSION_1_3_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_1_3') or contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define VERSION_1_4 VERSION_1_4_EXTENSIONS
#define VERSION_1_4_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_1_4') or contains(@name, 'VERSION_1_3') or contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>

#define VERSION_1_5 VERSION_1_5_EXTENSIONS
#define VERSION_1_5_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_1_5') or contains(@name, 'VERSION_1_4') or contains(@name, 'VERSION_1_3') or contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>

#define VERSION_2_0 VERSION_2_0_EXTENSIONS
#define VERSION_2_0_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_2_0') or contains(@name, 'VERSION_1_5') or contains(@name, 'VERSION_1_4') or contains(@name, 'VERSION_1_3') or contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define VERSION_2_1 VERSION_2_1_EXTENSIONS
#define VERSION_2_1_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'VERSION_2_1') or contains(@name, 'VERSION_2_0') or contains(@name, 'VERSION_1_5') or contains(@name, 'VERSION_1_4') or contains(@name, 'VERSION_1_3') or contains(@name, 'VERSION_1_2')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define ARB_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'ARB')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define EXT_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'EXT')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END) \
</xsl:if></xsl:for-each>
    
#define IMPORTANT_EXTENSIONS(NAME, FUNC, CONST, END) \
  MAX_VERSION_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:for-each select="extensions/gl/extension"><xsl:if test="contains(@name, 'ARB') or contains(@name, 'EXT')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END)<xsl:if test="not(position() = last())"> \
</xsl:if></xsl:if></xsl:for-each>
    
#define CRITICAL_EXTENSIONS(NAME, FUNC, CONST, END) \
  MAX_VERSION_EXTENSIONS(NAME, FUNC, CONST, END) \
<xsl:apply-templates select="extensions/gl/extension" />
<xsl:text>



</xsl:text>
</xsl:template>

<xsl:template match="extension"><xsl:if test="contains(@name, 'ARB')">  EXTENSION_<xsl:value-of select="@name"/>(NAME, FUNC, CONST, END)<xsl:if test="not(position() = last())"> \
</xsl:if></xsl:if></xsl:template>

  <xsl:template match="constant">  CONST(<xsl:value-of select="@name"/>, <xsl:value-of select="@value"/>) \
</xsl:template>

  <xsl:template match="function">  FUNC(<xsl:value-of select="@returnType"/>, <xsl:value-of select="@name"/>, <xsl:value-of select="translate(@name,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>, (<xsl:apply-templates select="param" />)) \
</xsl:template>

  <xsl:template match="param">
    <xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/><xsl:if test="not(position() = last())">, </xsl:if>
  </xsl:template>
</xsl:stylesheet>
